home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / BORL_TIP / TI1000 / TI1202.ASC < prev    next >
Text File  |  1994-09-20  |  13KB  |  590 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Pascal                                 NUMBER  :  1202
  8.   VERSION  :  All
  9.        OS  :  DOS
  10.      DATE  :  September 17, 1994                       PAGE  :  1/10
  11.  
  12.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  13.  
  14.  
  15.  
  16.  
  17.  
  18. VESA DRIVERS
  19.  
  20.      With the release of Borland Pascal for Objects 7.0,
  21. programmers can now use BGI graphics to obtain 16 color
  22. resolutions of 800 X 600, 1024 X 768, and 1280 X 1024.
  23.  
  24. HOW TO USE THE VESA16.BGI DRIVER
  25.  
  26.      The VESA unit included with this Tech Info Sheet shows you a
  27. simple way to use  the new VESA driver in your own program. To
  28. get started, you need only include the word VESA in your uses
  29. clause and then call the included Initialize procedure. So the
  30. simplest possible program using the VESA driver might look like
  31. this:
  32.  
  33. program Simple;
  34. uses
  35.    Graph,
  36.    Vesa;
  37. begin
  38.   Initialize('c:\bp\bgi');
  39.   OutText('Hello');
  40.   ReadLn;
  41.   CloseGraph;
  42. end.
  43.  
  44.  
  45. This program assumes, of course, that you have the VESA unit
  46. available on disk and that your BGI drivers are kept in the
  47. C:\BP\BGI sub directory. If the system this program is run on
  48. does not support the VESA BIOS then the code in the VESA unit
  49. will automatically switch your computer into the highest
  50. available mode.
  51.       The next few paragraphs describe a somewhat more complex
  52. program, also included in this TI, which shows you how to use the
  53. new high resolution modes. This program is called VesaSamp.Pas.
  54. It uses the VESA unit, also listed below, to load the BGI  VESA
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.   PRODUCT  :  Pascal                                 NUMBER  :  1202
  68.   VERSION  :  All
  69.        OS  :  DOS
  70.      DATE  :  September 17, 1994                       PAGE  :  2/10
  71.  
  72.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  73.  
  74.  
  75.  
  76.  
  77. graphics driver into memory. The program then shows you the
  78. highest available resolution on your system.
  79.      In order to simplify the process of entering graphics mode,
  80. the VESA UNIT provides you with an easy to use Initialize
  81. procedure which takes the location of the BGI drivers as its sole
  82. parameter. This procedure will automatically switch you into
  83. graphics mode, and also initialize several useful variables.
  84.      As presented below, program VesaSamp.Pas hardcodes the
  85. location of the BGI drivers as being in the C:\BP\BGI sub
  86. directory. If this is not the case on your system, then you need
  87. to change this code before running the program. For instance, if
  88. you store the BGI drivers in the D:\PASCAL\DRIVERS sub directory,
  89. then you should change the call that reads:
  90.  
  91. Initialize('c:\bp\bgi');
  92.  
  93. so that it reads:
  94.  
  95. Initialize('d:\pascal\drivers');
  96.  
  97. If you have the BGI drivers available in the current sub
  98. directory, then you would initialize the graphics system with the
  99. following code:
  100.  
  101. Initialize('');
  102.  
  103. After correctly setting up the Initialize procedure, the VesaSamp
  104. program will pop into graphics mode and show you the highest
  105. available resolution.
  106.  
  107. WHAT IS THE VESA BIOS?
  108.  
  109.      The VESA BIOS represents a standard for accessing SUPER VGA
  110. resolutions. The problem it addresses is that there are many
  111. different Super VGA boards on the market, but no common API for
  112. addressing them.
  113.      To attempt to bring some sort of sanity to this madness, the
  114. Video Electronics Standards Association (VESA) defined a set of
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.   PRODUCT  :  Pascal                                 NUMBER  :  1202
  128.   VERSION  :  All
  129.        OS  :  DOS
  130.      DATE  :  September 17, 1994                       PAGE  :  3/10
  131.  
  132.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  133.  
  134.  
  135.  
  136.  
  137. BIOS extensions that allow programmers to ask the video adapter
  138. about its abilities. These BIOS extensions are sometimes
  139. implemented directly in ROM and sometimes loaded into memory by a
  140. special TSR. Many of these TSRs are available on the Compuserve
  141. Information Service (1-800-848-8990).
  142.      Since it is always possible that the video card on any
  143. particular system might not support the VESA extensions, you
  144. should be aware that your program might not actually run in a
  145. high resolution mode. But the Borland Graphics Interface will
  146. find the highest available mode and then switch you into it.
  147.      The rest of this TI contains the sample code which shows you
  148. how to use the VESA BGI driver. You should be aware of the fact
  149. that it is necessary for the VESA .PAS unit to automatically
  150. detect whether or not you have compiled your program as a
  151. protected mode application. In other words, if you want to copy
  152. code from the VESA unit directly into your program, make sure you
  153. are getting the DOS code for DOS apps and the DPMI code for DPMI
  154. apps.
  155.  
  156. program VesaSamp;
  157. {
  158.  A test program for unit Vesa
  159.  which provides Super VGA Resolutions
  160. }
  161. uses
  162.   Graph,
  163.   Vesa;
  164.  
  165. { Converts an integer to a string }
  166. function Int2Str(L : LongInt) : string;
  167. var
  168.   S : string;
  169. begin
  170.   Str(L, S);
  171.   Int2Str := S;
  172. end; { Int2Str }
  173.  
  174. var
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.   PRODUCT  :  Pascal                                 NUMBER  :  1202
  188.   VERSION  :  All
  189.        OS  :  DOS
  190.      DATE  :  September 17, 1994                       PAGE  :  4/10
  191.  
  192.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  193.  
  194.  
  195.  
  196.  
  197.   S: String;
  198. begin
  199.   Initialize('c:\bp\bgi');
  200.   Rectangle(0,0,MaxX,MaxY);
  201.   SetColor(LightGreen);
  202.   SetBkColor(Blue);
  203.   SetTextStyle(TriplexFont, HorizDir, 8);
  204.   S := 'MaxX = ' + Int2Str(MaxX);
  205.   OutTextXY((MaxX Div 2)  - (TextWidth(S) div 2),
  206.             (MaxY div 2) - 220, S);
  207.   S := 'MaxY = ' + Int2Str(MaxY);
  208.   OutTextXY((MaxX Div 2) - (TextWidth(S) div 2), (MaxY div 2) -
  209. 80, S);
  210.   S := 'MemAvail = ' + Int2Str(MemAvail);
  211.   OutTextXY((MaxX Div 2)  - (TextWidth(S) div 2), (MaxY div 2) +
  212. 60, S);
  213.   ReadLn;
  214.   CloseGraph;
  215. end.
  216.  
  217. {***************************************************}
  218. {******************** VESA UNIT *********************}
  219. {***************************************************}
  220.  
  221. unit Vesa;
  222. {
  223.         Add this unit to programs that want Vesa support
  224.   for high resolutions such as 800 X 600, 1024 X 768
  225.   and 1280 X 1024. If Vesa is not supported on a system
  226.   the code automatically defaults to an available driver
  227.   such as EGAVGA.
  228.        To Initialize the graphics system, just call
  229.   Initialize with the path to VESA.BGI as the sole
  230.   parameter. Pass an empty string if the driver
  231.   is in the current subdirectory.
  232.        The code will automatically detect if you are
  233.   running in protected mode or real mode.
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.   PRODUCT  :  Pascal                                 NUMBER  :  1202
  248.   VERSION  :  All
  249.        OS  :  DOS
  250.      DATE  :  September 17, 1994                       PAGE  :  5/10
  251.  
  252.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  253.  
  254.  
  255.  
  256.  
  257.   Examples:
  258.     Initialize('c:\bp\bin');
  259.     Initialize('');
  260. }
  261. Interface
  262.  
  263. uses
  264.   Graph {$IfDef DPMI}, WinApi {$EndIf};
  265.  
  266. const
  267.   VESA16Modes: array[0..2] of Word =
  268.     ($0102, $0104, $0106);
  269.  
  270. type
  271.   VgaInfoBlock = record
  272.     VESASignature: array[0..3] of Byte;
  273.     VESAVersion: Word;
  274.     OEMStringPtr: Pointer;
  275.     Capabilities: array[0..3] of Byte;
  276.     VideoModePtr: Pointer;
  277.   end;
  278.  
  279. var
  280.   MaxColor,
  281.   MaxX, MaxY: Integer;
  282.  
  283. procedure Initialize(PathToDriver: String);
  284. implementation
  285.  
  286. var
  287.   VESA16      : Integer;  { Driver number of 16 color driver }
  288.  
  289. function GetHighestCap(Table: Pointer; Modes: Word; Size:
  290. Integer): Integer;
  291.   near; assembler;
  292. asm
  293.         XOR     AX,AX
  294.         LES     DI, Table
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.   PRODUCT  :  Pascal                                 NUMBER  :  1202
  308.   VERSION  :  All
  309.        OS  :  DOS
  310.      DATE  :  September 17, 1994                       PAGE  :  6/10
  311.  
  312.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  313.  
  314.  
  315.  
  316.  
  317. @1:
  318.         MOV     SI, Modes
  319.         ADD     SI, Size
  320.         ADD     SI, Size
  321.         MOV     BX, ES:[DI]
  322.         CMP     BX, 0FFFFH
  323.         JE      @4
  324.         INC     DI
  325.         INC     DI
  326.         MOV     CX,Size
  327. @2:
  328.         CMP     BX,[SI]
  329.         JZ      @3
  330.         DEC     SI
  331.         DEC     SI
  332.         LOOP    @2
  333. @3:
  334.         CMP     AX,CX
  335.         JA      @1
  336.         MOV     AX,CX
  337.         JMP     @1
  338. @4:
  339. end;
  340.  
  341. {$IFDEF DPMI}
  342. type
  343.   TRealRegs = record
  344.     RealEDI: Longint;
  345.     RealESI: Longint;
  346.     RealEBP: Longint;
  347.     Reserved: Longint;
  348.     RealEBX: Longint;
  349.     RealEDX: Longint;
  350.     RealECX: Longint;
  351.     RealEAX: Longint;
  352.     RealFlags: Word;
  353.     RealES: Word;
  354.     RealDS: Word;
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.   PRODUCT  :  Pascal                                 NUMBER  :  1202
  368.   VERSION  :  All
  369.        OS  :  DOS
  370.      DATE  :  September 17, 1994                       PAGE  :  7/10
  371.  
  372.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  373.  
  374.  
  375.  
  376.  
  377.     RealFS: Word;
  378.     RealGS: Word;
  379.     RealIP: Word;
  380.     RealCS: Word;
  381.     RealSP: Word;
  382.     RealSS: Word;
  383.   end;
  384.  
  385. function DetectVesa16: Integer; far; assembler;
  386. var
  387.   Segment, Selector, VesaCap: Word;
  388. asm
  389. {$IFOPT G+}
  390.         PUSH    0000H
  391.         PUSH    0100H
  392. {$ELSE}
  393.         XOR     AX,AX
  394.         PUSH    AX
  395.         INC     AH
  396.         PUSH    AX
  397. {$ENDIF}
  398.         CALL    GlobalDosAlloc
  399.         MOV     Segment,DX
  400.         MOV     Selector,AX
  401.         MOV     DI,OFFSET RealModeRegs
  402.         MOV     WORD PTR [DI].TRealRegs.RealSP, 0
  403.         MOV     WORD PTR [DI].TRealRegs.RealSS, 0
  404.         MOV     WORD PTR [DI].TRealRegs.RealEAX, 4F00H
  405.         MOV     WORD PTR [DI].TRealRegs.RealES, DX
  406.         MOV     WORD PTR [DI].TRealRegs.RealEDI, 0
  407.         MOV     AX,DS
  408.         MOV     ES,AX
  409.         MOV     AX,0300H
  410.         MOV     BX,0010H
  411.         XOR     CX,CX
  412.         INT     31H
  413.         MOV     DI,OFFSET RealModeRegs
  414.         MOV     AX,grError
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.   PRODUCT  :  Pascal                                 NUMBER  :  1202
  428.   VERSION  :  All
  429.        OS  :  DOS
  430.      DATE  :  September 17, 1994                       PAGE  :  8/10
  431.  
  432.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  433.  
  434.  
  435.  
  436.  
  437.         PUSH    AX
  438.         CMP     WORD PTR [DI].TRealRegs.RealEAX,004FH
  439.         JNZ     @Exit
  440.         POP     AX
  441.         MOV     ES,Selector
  442.         XOR     DI,DI
  443.         CMP     ES:[DI].VgaInfoBlock.VESASignature.Word[0], 'EV'
  444.         JNZ     @Exit
  445.         CMP     ES:[DI].VgaInfoBlock.VESASignature.Word[2], 'AS'
  446.         JNZ     @Exit
  447.         MOV     AX,0000
  448.         MOV     CX,1
  449.         INT     31H
  450.         MOV     VesaCap,AX
  451.         MOV     DX,ES:[DI].VgaInfoBlock.VideoModePtr.Word[2]
  452.         MOV     CX,4
  453.         XOR     AX,AX
  454. @Convert:
  455.         SHL     DX,1
  456.         RCL     AX,1
  457.         LOOP    @Convert
  458.         ADD     DX,ES:[DI].VgaInfoBlock.VideoModePtr.Word[0]
  459.         ADC     AX,0
  460.         MOV     CX,AX
  461.         MOV     BX,VesaCap
  462.         MOV     AX,0007H
  463.         INT     31H
  464.         INC     AX
  465.         XOR     CX,CX
  466.         MOV     DX,0FFFFH
  467.         INT     31H
  468.         MOV     ES,BX
  469.         PUSH    ES
  470.         PUSH    DI
  471. {$IFOPT G+}
  472.         PUSH    OFFSET Vesa16Modes
  473.         PUSH    0003H
  474. {$ELSE}
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.   PRODUCT  :  Pascal                                 NUMBER  :  1202
  488.   VERSION  :  All
  489.        OS  :  DOS
  490.      DATE  :  September 17, 1994                       PAGE  :  9/10
  491.  
  492.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  493.  
  494.  
  495.  
  496.  
  497.         MOV     SI, OFFSET Vesa16Modes
  498.         PUSH    SI
  499.         MOV     AX, 5
  500.         PUSH    AX
  501. {$ENDIF}
  502.         CALL    GetHighestCap
  503.         PUSH    AX
  504.         MOV     BX,VesaCap
  505.         MOV     AX,0001H
  506.         INT     31H
  507. @Exit:
  508.         PUSH    Selector
  509.         CALL    GlobalDosFree
  510.         POP     AX
  511. end;
  512. {$ELSE}
  513. function DetectVesa16: Integer; far; assembler;
  514. var
  515.   VesaInfo: array[0..255] of Byte;
  516. asm
  517.         MOV     AX,SS
  518.         MOV     ES,AX
  519.         LEA     DI,VesaInfo
  520.         MOV     AX,4F00H
  521.         INT     10H
  522.         CMP     AX,004FH
  523.         MOV     AX,grError
  524.         JNZ     @Exit
  525.         CMP     ES:[DI].VgaInfoBlock.VESASignature.Word[0], 'EV'
  526.         JNZ     @Exit
  527.         CMP     ES:[DI].VgaInfoBlock.VESASignature.Word[2], 'AS'
  528.         JNZ     @Exit
  529.         LES     DI,ES:[DI].VgaInfoBlock.VideoModePtr
  530.         PUSH    ES
  531.         PUSH    DI
  532.         MOV     AX, OFFSET Vesa16Modes
  533.         PUSH    AX
  534.         MOV     AX,3
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.   PRODUCT  :  Pascal                                 NUMBER  :  1202
  548.   VERSION  :  All
  549.        OS  :  DOS
  550.      DATE  :  September 17, 1994                       PAGE  :  10/10
  551.  
  552.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  553.  
  554.  
  555.  
  556.  
  557.         PUSH    AX
  558.         CALL    GetHighestCap
  559. @Exit:
  560. end;
  561. {$ENDIF}
  562.  
  563. procedure Initialize(PathToDriver: String);
  564. var
  565.   MaxColor,
  566.   ErrorCode,
  567.   GraphMode,
  568.   GraphDriver: Integer;
  569. begin
  570.   VESA16 := InstallUserDriver('VESA16', @DetectVESA16);
  571.   GraphDriver := Detect;
  572.   InitGraph(GraphDriver, GraphMode, PathToDriver);
  573.   ErrorCode := GraphResult;
  574.   if ErrorCode <> grOK then begin
  575.     WriteLn('Graphics error: ', GraphErrorMsg(ErrorCode));
  576.     ReadLn;
  577.     Halt;
  578.   end;
  579.   MaxX := GetMaxX;
  580.   MaxY := GetMaxY;
  581.   MaxColor := GetMaxColor;
  582. end;
  583. end.
  584.  
  585.  
  586. DISCLAIMER: You have the right to use this technical information
  587. subject to the terms of the No-Nonsense License Statement that
  588. you received with the Borland product to which this information
  589. pertains.
  590.